Imports System.Windows.Forms
Imports Microsoft.SqlServer.Management
Imports Microsoft.SqlServer.Management.Smo

Imports Microsoft.SqlServer.Server
'Imports SQLDMO
Public Class gFrmSQLServer
    'Dim sqldmoApp As SQLDMO.Application
    'Dim sqldmoList As SQLDMO.NameList
    Dim sqlmag As Microsoft.SqlServer.Management.Nmo.Application
    Public sqlselected As String
    Function getNames() As Boolean
        Dim dtlSQLServers As DataTable
        dtlSQLServers = SmoApplication.EnumAvailableSqlServers(False)
        For Each drServer As DataRow In dtlSQLServers.Rows
            Me.sqllist.Items.Add(drServer("Name"))
        Next
        Return True
    End Function

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub gFrmSQLServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''getNames()
    End Sub

    Private Sub sqllist_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles sqllist.ItemCheck
        sqlselected = sqllist.Items.Item(e.Index).ToString
        MsgBox(sqlselected)
    End Sub

    Private Sub sqllist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sqllist.SelectedIndexChanged

    End Sub
End Class
